import React from 'react';
import styles from '../style/toplist.scss';
export default class Page extends React.Component {
	render(){
        let that = this;
        //当前页码
        let cur = this.props.current;
        //显示分页按钮
        let pageNum = [];
        let begin;
        let len;
        if(that.props.totalPage > 5){
            len = 5;
            if(cur >= (that.props.totalPage-2)){
                begin = that.props.totalPage - 4;
            }else if(cur <= 3){
                begin = 1;
            }else{
                begin = cur - 2;
            }
        }else{
            len = that.props.totalPage;
            begin = 1;
        }
        //根据返回的总记录数计算当前页显示的数据
        for(let i = 0; i < len; i ++){
            let cur = this.props.current;
            let showI = begin + i;
            if(cur == showI){
                pageNum.push({num : showI, cur : true});
            }else{
                pageNum.push({num : showI, cur : false});
            }
         }
        return(
          <div>
              <div className={styles.paginationDiv}>{/*`${value.class} ${value.class2}`'prev disable'*/}
                  	<a className={this.props.current == '1' ? styles.prevNone : styles.prev} onClick={this.props.goPrev.bind(this)}>&lt;</a>
                    <span>
                        {
                            pageNum.map(function(curPageNum){
                                return(
                                    <a onClick = {that.props.pageClick.bind(that,curPageNum.num)} className={curPageNum.cur ? styles.pageNumsNow : styles.pageNums}>{curPageNum.num}</a>
                                )
                            })
                        }
                    </span>
                  <a className={this.props.current == this.props.totalPage? styles.prevNone : styles.prev} onClick={this.props.goNext.bind(this)}>&gt;</a>
              </div>
          </div>
        )
    }

}